package org.xue.snowmall.group.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.xue.snowmall.group.entity.GroupEntity;
import org.xue.snowmall.group.service.GroupService;
import org.xue.snowmall.common.utils.PageUtils;
import org.xue.snowmall.common.utils.R;



/**
 * 
 *
 * @author zy
 * @email 2067065884@qq.com
 * @date 2021-09-27 10:40:40
 */
@RestController
@RequestMapping("group/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = groupService.queryPage(params);
        List<GroupEntity> list = page.getList();
        for (GroupEntity groupEntity : list) {
            if (groupEntity.getGsmGroupFreight().equals("0")) {
                groupEntity.setGsmGroupFreight("包邮");
            }
            if (groupEntity.getGsmGroupFreight().equals("1")) {
                groupEntity.setGsmGroupFreight("不包邮");
            }
            if (groupEntity.getGsmGroupBonus().equals("0")) {
                groupEntity.setGsmGroupBonus("由返金");
            }
            if (groupEntity.getGsmGroupBonus().equals("1")) {
                groupEntity.setGsmGroupBonus("无返金");
            }
            if (groupEntity.getGsmStatus().equals("0")) {
                groupEntity.setGsmStatus("正在进行");
            }
            if (groupEntity.getGsmStatus().equals("0")) {
                groupEntity.setGsmStatus("已经结束");
            }
        }
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{gsmGroupId}")
    public R info(@PathVariable("gsmGroupId") Long gsmGroupId){
		GroupEntity group = groupService.getById(gsmGroupId);

        return R.ok().put("group", group);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GroupEntity group){
        group.setGsmStatus("0");
		groupService.save(group);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GroupEntity group){
		groupService.updateById(group);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] gsmGroupIds){
		groupService.removeByIds(Arrays.asList(gsmGroupIds));

        return R.ok();
    }

}
